using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using XNALibrary.Game;

namespace XNALibrary.Cameras
{
    public class CameraPath : Camera
    {
        private List<Vector3> path;
        private float interval;
        private Vector3 destiny;
        private float elapsed;
        private int count;

        public Vector3 Destiny
        {
            get { return destiny; }
            set { destiny = value; }
        }

        public float Interval
        {
            get { return interval; }
            set { interval = value; }
        }

        public CameraPath(Vector3 position, ref List<Vector3> CPath) : base(position)
        {
            path = CPath;
            interval = 6;
            Position = path[0];
            destiny = path[0];
        }

        public void Update()
        {
            elapsed += (float)BaseGame.gameTime.ElapsedRealTime.TotalSeconds;
            if (((int)elapsed % interval) == 1)
            {
                elapsed += 1;
                count++;
                destiny = path[count % path.Count];
            }

            this.position.X = Position.X + ((destiny.X - Position.X) / 100.0f);
            this.position.Y = Position.Y + ((destiny.Y - Position.Y) / 100.0f);
            this.position.Z = Position.Z + ((destiny.Z - Position.Z) / 100.0f);

            View = Matrix.CreateLookAt(Position, Lookat, Vector3.Up);
        }
    }
}
